package com.whatever;

import java.util.Random;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.*;

public class ColorBall {
	private int posX;
	private int posY;
	private int velX;
	private int velY;
	private int width;
	private int height;
	private int id;
	private int radius;
	private int ballColor;
	private static int[] vels = {
			1,2,3
	};
	private static int[] radii = {
		100, 110, 120
	};
	private int[] color = {
			0xff0000ff, //BLUE
			0xff00ff00, //GREEN
			0xff00ffff, //CYAN
			0xffff0000, //RED
			0xffff00ff, //PINK
			0xffffff00, //BROWN?
			0xffffffff  //WHITE
	};
	private static int count = 1;
	private Bitmap bitMap;
	private Random rand = new Random();
	
	public ColorBall (Context cxt, int x, int y) {
		BitmapFactory.Options bitMapFactory = new BitmapFactory.Options();
		bitMapFactory.inJustDecodeBounds = true;
		
		id = count;
		count++;
		radius = radii[rand.nextInt(radii.length)];
		velX = vels[rand.nextInt(vels.length)];
		velY = vels[rand.nextInt(vels.length)];
		posX = x;
		posY = y;
		ballColor = color[rand.nextInt(90) % color.length];
		
		WindowManager windowManager = (WindowManager)cxt.getSystemService(Context.WINDOW_SERVICE);
		Display display = windowManager.getDefaultDisplay();
		this.width = display.getWidth();
		this.height = (display.getHeight() - 150);
		
		while(posX > width - radius) {
			posX--;
		}
		while(posX < 0 + radius) {
			posX++;
		}
		while(posY > height - radius) {
			posY--;
		}
		while(posY < 0 + radius) {
			posY++;
		}
	}
	
	public void setPosX(int x) {
		this.posX = x;
	}
	
	public void setPosY(int y) {
		this.posY = y;
	}
	
	public void setVelX(int x) {
		this.velX = x;
	}
	
	public void setVelY(int y) {
		this.velY = y;
	}
	
	public static void addVel(int s) {
		for(int i = 0; i < vels.length; i++) {
			vels[i] += s;
		}
	}
	
	public static void subtractVel(int s) {
		for(int i = 0; i < vels.length; i++) {
			vels[i] -= s;
		}
	}
	
	public void setRadius(int r) {
		this.radius = r;
	}
	
	public static void addRadius(int r) {
		for(int i = 0; i < radii.length; i++) {
			radii[i] += r;
		}
	}
	
	public static void subtractRadius(int r) {
		for(int i = 0; i < radii.length; i++) {
			radii[i] -= r;
		}
	}
	
	public int getPosX() {
		return posX;
	}
	
	public int getPosY() {
		return posY;
	}
	
	public int getVelX() {
		return velX;
	}
	
	public int getVelY() {
		return velY;
	}
	
	public static int getAverageVel() {
		return vels[1];
	}
	
	public int getId() {
		return id;
	}

	public int getRadius() {
		return radius;
	}
	
	public static int getAverageRadius() {
		return radii[1];
	}
	
	public int getColor() {
		return ballColor;
	}
	
	public Bitmap getBitmap() {
		return bitMap;
	}
	
	public void onMove(int x, int y, ColorBall colorball) {
		
		if(x > width - radius) {
			posX -= velX;
			posY -= velY;
			velX = -velX;
		}
		
		if(x < 0 + radius) {
			posX -= velX;
			posY -= velY;
			velX = -velX;
		}
		
		if(y > height - radius) {
			posX -= velX;
			posY -= velY;
			velY = -velY;
		}
		
		if(y < 0 + radius) {
			posX -= velX;
			posY -= velY;
			velY = -velY;
		}
		
		//System.out.println("PosX: " + posX + ", PosY: " + posY + ", VelX: " + velX + ", VelY: " + velY);
		
		posX += velX;
		posY += velY;
	}
}
